from PositionInfo import PositionInfo
from Constant import *

class FileReader():
    
    def __init__(self):
        self.__001_initialInstanceVariable()
        
    def __001_initialInstanceVariable(self):
        #list of each point information
        self.list_trajInfo = []
        
    def ACT001_readFromFile(self, fileName):
        self.__001_initialInstanceVariable()
        fp = file(fileName)
        list_pointInfo = []
        #read from file
        isEnd = False
        isAddList = False
        while not isEnd :
            temp = fp.readline()
            if temp.startswith(TRAJ_LABEL_START) :  #encounter START label
                pass
            elif temp.startswith(TRAJ_LABEL_BRK) :  #encounter BRK label
                isAddList = True
            elif temp.startswith(TRAJ_LABEL_END) :  #encounter END label
                isAddList = True
                isEnd = True
            else :  #encounter data
                temp = temp.split()
                list_pointInfo.append(PositionInfo(int(temp[0]), int(temp[1]), int(temp[2]), temp[3]))
            if isAddList :  #add new trajectory data to list
                self.list_trajInfo.append(list_pointInfo)
                list_pointInfo = []
                isAddList = False
        #close file
        fp.close()
            
    def GET001_list_trajInfo(self):
        return self.list_trajInfo
